<?php include_once('../config/db.php'); 
	   include_once('../functions/category.php');

		if(isset($_REQUEST['submit_noq'])){
		$noq = $_REQUEST['noq'];
		if($noq >= 1) $var = 1;
		
	}
	if(isset($_REQUEST['save'])){
		if(isset($_REQUEST['i'])){
			if(addCategory($_REQUEST['i'])){
				$_SESSION['success'] = 'Item added successfully';
				
			}
			else{
				$_SESSION['error'] = 'Cannot add item, try again later';
				
			}
			
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css"/>
<title>Add Category</title>
</head>
<body>
<div id="header">
<div id="logo">
  <p>&nbsp;</p>
  <div id="apDiv1"><img src="../image/logo.png" alt="" width="500" height="100" /></div>
  <p>&nbsp;</p>
</div>
</div>
<div id="con-body">
<?php include 'navigation.php';?>

<?php /*Messages*/?>
	<?php 
		if(isset($_SESSION['success'])){
			echo '<div class="succes">'.$_SESSION['success'].'</div>';
			unset($_SESSION['success']);
		}
		else if(isset($_SESSION['error'])){
			echo '<div class="error">'.$_SESSION['error'].'</div>';
			unset($_SESSION['error']);
		}
		?>
<?php /*End Messages*/?>

	<?php if(!isset($var)):?>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    	<label>Select no. of category you want to add.</label>
    	<select name="noq">
        	
        	<?php for($v = 1; $v <= 50; $v++):?>
        	<option value="<?php echo $v;?>"><?php echo $v;?></option>
            <?php endfor;?>
        </select>
        <input type="submit" name="submit_noq" value="Submit" class="submit" />
    </form>
    <?php endif;?>
    
    <?php if(isset($var)):?>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    	<input type="hidden" name="noi" value="<?php echo $noq;?>"/>
     
     <?php for($i = 1; $i<=$noq; $i++):?>
		<table width="437" border="0">
    <tr>
      <td>Category Name: </td>
      <td><input name="i[<?php echo $i?>][cname]" type="text" id="c_name" size="40" /></td>
    </tr>
    <tr>
      <td>Description: </td>
      <td><textarea name="i[<?php echo $i ?>][cdesc]" cols="40" rows="5" id="c_desc"></textarea>
       </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td></td>
    </tr>
</table> <?php endfor;?>

           <!--<input type="checkbox" name="open_to<?php //echo $i;?>[]" value="kinder" /> Kinder
            <input type="checkbox" name="open_to<?php //echo $i;?>[]" value="grade1" /> Grade 1
            
        	<label for="fasd">Question</label>
        	<textarea name="q<?php //echo $i; ?>" rows="10%" cols="10%" ></textarea>-->
    <input name="save" type="submit" class="blue" id="save" value="Save Materials" /><?php endif;?>
	</form>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></p>
</body>
</html>